/**
 *  This file is part of AugeasWH.
 *
 *  AugeasWH. is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AugeasWH. is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AugeasWH.  If not, see <http://www.gnu.org/licenses/>.
 */

package cz.fit.vutbr.pis2012.augeaswh.managers;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import cz.fit.vutbr.pis2012.augeaswh.persistence.Discount;

@Stateless
public class DiscountsManager {
	
	@PersistenceContext
	private EntityManager em;
	
	public List<Discount> getDiscounts() {
		@SuppressWarnings("unchecked")
	//	List<Discount> list = em.createQuery("SELECT d FROM Discount d WHERE d.stock_type_id = :stockTypeId").setParameter("stockTypeId", stockType.getId()).getResultList();
		List<Discount> list = em.createQuery("SELECT d FROM Discount d").getResultList();

		System.out.println(list.size());
		return list;
	}
	
	public void deleteDiscount(Discount item) {
		if (item != null)
			em.remove(em.merge(item));
	}
	
	public void saveOrUpdateDiscount(Discount item) {
		if (item != null) {
			em.merge(item);
		}
	}

}
